package com.restaurant.application.util;

import com.nebutown.generation.PickableBean;

import java.util.Objects;

public class ResultBean<T extends PickableBean> implements PickableBean {

    public enum STATUS {
        success, fail, error
    }

    private int code;
    private String message;
    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        ResultBean<?> that = (ResultBean<?>) o;
        return code == that.code &&
                Objects.equals(message, that.message) &&
                Objects.equals(data, that.data);
    }

    @Override
    public int hashCode() {
        return Objects.hash(code, message, data);
    }

    @Override
    public PickableBean duplicate() {
        ResultBean result = new ResultBean();
        result.code = this.code;
        result.message = this.message;
        result.data = this.data;
        return result;
    }

    @Override
    public Object getValueOf(String name) {
        switch (name) {
            case "code":
                return getCode();
            case "message":
                return getMessage();
            case "data":
                return getData();
            default:
                return this;
        }
    }

    @Override
    public String toString() {
        return "ResultBean{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
